package five_publishAndSubscribe;

import com.rabbitmq.client.Channel;
import util.RabbitMqUtils;

import java.util.Scanner;

/**
 * @BelongsProject: RabbitMQ
 * @BelongsPackage: five_publishAndSubscribe
 * @Author: HUI
 * @CreateTime: 2022-04-13 20:00
 * @Description: 发布者
 */
public class LogsProducer {
    private static final String EXCHANGE_NAME = "logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //声明一个 Exchange，名字、类型
        channel.exchangeDeclare(EXCHANGE_NAME,"fanout");


        //从控制台当中接受信息
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String message = scanner.next();
            channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());
            System.err.println("发送消息完成:" + message);

        }
    }
}
